import numpy as np
import pandas as pd


input_example = [[-0.783778, 1.783778, 0.026, 0.0, 0.000431, 0.002889, 0.000444, 0.059111, 0.100889, 2145302.755556, 0.135066, 0.004496, 0.073298, 0.864934, 0.003251, 0.004196, 1225196032.0, 498422272.0, 35434.666667, 36029.866667, 23257771.25, 2145302.755556],
 [-0.863111, 1.863111, 0.072889, 0.0, 0.0, 0.000889, 0.0, 0.026222, 0.030667, 563609.6, 0.079898, 0.003494, 0.048774, 0.920102, 0.005568, 0.00384, 616874496.0, 967455232.0, 2587.2, 3118.066667, 3363980.0, 563609.6],
 [-0.773778, 1.773778, 0.155333, 0.0, 0.0, 0.000444, 0.0, 0.024889, 0.036, 6830671.644444, 0.081268, 0.00348, 0.049573, 0.918732, 0.005644, 0.003863, 634319360.0, 965734912.0, 2614.533333, 3022.066667, 3338474.5, 6830671.644444],
 [-0.777333, 1.777333, 0.018889, 0.0, 0.000222, 0.003556, 0.0, 0.054, 0.110667, 8691165.866667, 0.15591, 0.006623, 0.088744, 0.84409, 0.003981, 0.004622, 1398518272.0, 1943880192.0, 31833.466667, 32364.333333, 23702986.0, 8691165.866667]]


output_example = [[-0.783778, 1.783778, 0.026, 0.0, 0.000431, 0.002889, 0.000444, 0.059111, 0.100889, 2145302.755556, 0.135066, 0.004496, 0.073298, 0.864934, 0.003251, 0.004196, 1225196032.0, 498422272.0, 35434.666667, 36029.866667, 23257771.25, 2145302.755556],
 [-0.863111, 1.863111, 0.072889, 0.0, 0.0, 0.000889, 0.0, 0.026222, 0.030667, 563609.6, 0.079898, 0.003494, 0.048774, 0.920102, 0.005568, 0.00384, 616874496.0, 967455232.0, 2587.2, 3118.066667, 3363980.0, 563609.6],
 [-0.773778, 1.773778, 0.155333, 0.0, 0.0, 0.000444, 0.0, 0.024889, 0.036, 6830671.644444, 0.081268, 0.00348, 0.049573, 0.918732, 0.005644, 0.003863, 634319360.0, 965734912.0, 2614.533333, 3022.066667, 3338474.5, 6830671.644444],
 [-0.777333, 1.777333, 0.018889, 0.0, 0.000222, 0.003556, 0.0, 0.054, 0.110667, 8691165.866667, 0.15591, 0.006623, 0.088744, 0.84409, 0.003981, 0.004622, 1398518272.0, 1943880192.0, 31833.466667, 32364.333333, 23702986.0, 8691165.866667]]


def compare(o_e, o):
    assert isinstance(o_e, np.ndarray)
    assert isinstance(o, np.ndarray)
    if o_e.shape == o.shape:

        temp = o_e == o
        flag = True
        for row in temp:
            for col in row:
                flag = flag & col
        return flag
    else:
        return False


def ourpreprocess(temp_arr):
    no=temp_arr.shape[1]
    DSIZE=temp_arr.shape[0]
    for num in range(0,no):
        value=temp_arr[:,num]
        npArray=missing_value(value,DSIZE)
        temp_arr[:, num]=npArray
    return temp_arr


def missing_value(npArray, DSISE):
    missingValue = pd.notna(npArray)
    print(missingValue)

    # 存在缺失值，进行缺失值填充
    if (pd.isna(npArray).sum() > 0):
        npArray[np.isnan(npArray)] = 0.0

    return npArray


# 用例目的
print("该用例目的为：")
print("进行缺失值处理组件功能测试，在输入值为边界值状态下能否正常运行")

# 子用例编号
print("子用例编号：")
print("missing_value_3")

print("****************************")
print("当前输入为：")
# 输出用例设置
print(input_example)
# 输出用例设置

print("")

print("****************************")
print("当前输出为:")
# 输出处理后数据

output = ourpreprocess(np.array(input_example))
print(output)
# 输出处理后数据

print("****************************")
print("是否正确:")
# 输出对比结果
# 需要写一个compare函数
if compare(np.array(output_example), output):
    print("输出与预定目标相符")
else:
    print("输出与预定目标不符")
# 输出对比结果

print("\n")

